import { createContext, useRef } from 'react'
import ReduxHooksStore from './ReduxHooksStore'

export const ReduxContext = createContext(null)
/* 用于产生 reduxHooks 的 statex */
export function useCreateStore(reducer, initState) {
	const store = useRef(null)
	/* 如果存在不需要重新实例化 store */
	if (!store.current) {
		/* exportStore 抽离出核心方法 */
		store.current = new ReduxHooksStore(reducer, initState).exportStore()
	}
	return store.current
}
